<?php
	/*
		@copyright HungHau Holding
		@Name Le Van Tuong
		@Email levantuong435@gmail.com
	*/
	class Hunghau{
		public static function getServices($url){
			$ch = curl_init();
		    curl_setopt($ch,CURLOPT_URL,$url);
		    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
		    $content = curl_exec($ch);
		    curl_close($ch); 
			return $content;
		}
		public static function postServices1($url,$giatri){
			$ch = curl_init();
		    curl_setopt($ch,CURLOPT_URL,$url);
		    // thiet lập truyền giá trị
		    curl_setopt($ch, CURLOPT_POST, true);
		    curl_setopt($ch, CURLOPT_POSTFIELDS,
            "postvar1=value1&postvar2=value2&postvar3=value3");
		    // End post
		    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
		    $content = curl_exec($ch);
		    curl_close($ch); 
			return $content;
		}
		public static function postPage($url,$pvars,$referer,$timeout){
			if(!isset($timeout))
				$timeout = 30;
				$curl = curl_init();
				$post = http_build_query($pvars);
			if(isset($referer)){
				curl_setopt ($curl, CURLOPT_REFERER, $referer);
			}
			curl_setopt ($curl, CURLOPT_URL, $url);
			curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
			curl_setopt ($curl, CURLOPT_TIMEOUT, $timeout);
			//curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
			curl_setopt ($curl, CURLOPT_HEADER, 0);
			curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt ($curl, CURLOPT_POST, 1);
			curl_setopt ($curl, CURLOPT_POSTFIELDS, $post);
			//curl_setopt ($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
			$html = curl_exec ($curl);
			curl_close ($curl);
			return $html;
		}
		// Services php curl
		public static function postServices($url,$params){
			$curl = curl_init();
			$param = http_build_query($params);
			curl_setopt($curl,CURLOPT_URL,$url);
		    curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
		    // Thiết lập sử dụng POST
			curl_setopt($curl, CURLOPT_POST,count($param));
			curl_setopt($curl, CURLOPT_POSTFIELDS, $param);
			// End thiết lập sử dụng post
			$result = curl_exec ($curl);
			$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
			curl_close ($curl);
			if($http_code == 200){
				$result_arr = json_decode($result,true);
				return $result_arr;
			}else{
				return false;
			}
		}
	}
?>